package com.czx.strategy;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.czx.entity.Strategy;
import com.czx.mapper.StrategyMapper;
import com.czx.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StrategyContext {

    @Autowired
    private StrategyMapper strategyMapper;

    public <T> T getStrategy(String strategyId, String strategyType, Class<T> t) {
        Strategy strategy = strategyMapper.selectOne(Wrappers.<Strategy>lambdaQuery().eq(Strategy::getStrategyId, strategyId).eq(Strategy::getStrategyType, strategyType));
        T bean = SpringUtils.getBean(strategy.getBeanId(), t);
        return bean;
    }
}
